package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {
  /**
   * 分页查询
   * @param queryDTO
   */
  Page<SetmealVO> page(SetmealPageQueryDTO queryDTO);
  
  /**
   * 新增套餐
   * @param setmeal
   */
  @AutoFill(value = OperationType.INSERT)
  @Options(useGeneratedKeys = true, keyProperty = "id")
  @Insert("insert into setmeal (category_id, name, price, status, description, image, create_time, update_time, create_user, update_user) " +
      "VALUES (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser}) ")
  void insert(Setmeal setmeal);
  
  @Select("select * from setmeal where category_id = #{categoryId} and status = #{status}")
  List<Setmeal> list(Setmeal setmeal);
  
  @Select("select sd.name, sd.copies, d.image, d.description " +
      "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
      "where sd.setmeal_id = #{setmealId}")
  List<DishItemVO> getDishItemBySetmealId(Long setmealId);
  
  /**
   * 根据id查询套餐和包含的菜品
   */
  @Select("select s.*, c.name categoryName from setmeal s " +
      "left join category c on s.category_id = c.id where s.id = #{id}")
  SetmealVO findById(Long id);
  
  SetmealVO findSetmealWithDishesById(Long id);
  
  /**
   * 修改套餐
   */
  void update(Setmeal setmea);
  
  
  /**
   * 批量删除套餐
   * @param ids
   */
  void batchDel(List<Long> ids);
  
  /**
   * 根据条件统计套餐数量
   * @param map
   * @return
   */
  Integer countByMap(Map map);
}
